﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DependencyObjectTreeViewer
{
    public partial class DependencyObjectTreeForm : Form
    {
        public DependencyObjectTreeForm(DependencyObjectData dependencyObject)
        {
            InitializeComponent();

            PopulateTreeView(dependencyObject.LogicalTree, logicalTreeView.Nodes.Add(dependencyObject.LogicalTree.NodeType.ToString()));
            logicalTreeView.ExpandAll();

            PopulateTreeView(dependencyObject.VisualTree, visualTreeView.Nodes.Add(dependencyObject.VisualTree.NodeType.ToString()));
            visualTreeView.ExpandAll();
        }

        private void PopulateTreeView(DependencyObjectData.DependencyObjectTreeNode tree, TreeNode node)
        {
            foreach (DependencyObjectData.DependencyObjectTreeNode childNode in tree.Children)
            {
                PopulateTreeView(childNode, node.Nodes.Add(childNode.NodeType.ToString()));
            }
        }
    }
}